<%-- Copyright (c) 2002 BroadVision, Inc. All rights reserved              --%>
<%-- The product described in this manual may be protected by one or more  --%>
<%-- U.S. and International patents. The BroadVision One-To-One software   --%>
<%-- is covered by U.S. patent 5,710,887.                                  --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and the BroadVision logo are registered       --%>
<%-- trademarks, and BroadVision One-To-One is a trademark of BroadVision, --%>
<%-- Inc. IONA and Orbix are trademarks of IONA Technologies, Ltd. RSA,    --%>
<%-- MD5, and RC2 are trademarks of RSA Data Security, Inc. All other      --%>
<%-- trademarks, service marks, and trade names belong to their respective --%>
<%-- owners. BroadVision, Inc. disclaims any proprietary interest in the   --%>
<%-- marks and names of others.                                            --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

<c:set var="editIcon">
  <html:img   page="/mc/images/action/icon_edit.gif" 
    width="15" height="15" border="0" styleClass="actionIcon"
    altKey="em.image.alt.edit" titleKey="em.image.alt.edit" bundle="em"/>
</c:set>
<c:set var="deleteIcon">
  <html:img page="/mc/images/action/icon_delete.gif"
    width="15" height="15" border="0" styleClass="actionIcon"
    altKey="em.image.alt.delete" titleKey="em.image.alt.delete" bundle="em"/>
</c:set>
<c:set var="offlineImg">
   <html:img page="/mc/images/action/icon_offline.gif" 
   width="15" height="15" border="0" styleClass="actionIcon" 
   altKey="em.image.alt.setOffline" titleKey="em.image.alt.setOffline" bundle="em"/>
</c:set>
   <c:set var="onlineImg">
   <html:img page="/mc/images/action/icon_online.gif" 
   width="15" height="15" border="0" styleClass="actionIcon" 
   altKey="em.image.alt.setOnline" titleKey="em.image.alt.setOnline" bundle="em"/>
</c:set>


<script language="javascript"
	src="<%=request.getContextPath()%>/mc/js/date.js"
	type="text/javascript"></script>


<script type="text/javascript">

<%@ include file="/mc/common/jsutils.jsp" %>

function createNewRuleSet(action) {
  location = '<html:rewrite page="'+action+'" />'; 
  return false;
}

// function to POST form parameters to a ".do"
function doAction(action, myform){

    if( validateForm( myform)) {
      myform.action = '<html:rewrite page="'+action+'" />'; 
      myform.submit();
    }
    return true;
}


function validateFormBeforeDelete(myform)
{
  var found = 0;

  if ( myform.ruleSetOid == null ) 
   {
    alert( "<bean:message bundle="em" key="emarketing.ruleset.ruleSetSearch.javaScript.alert.selectRuleSet"/>")
    return false;
   }

  if ( myform.ruleSetOid.length == null ) 
  {
    if ( myform.ruleSetOid.checked == true )
      found = 1;
  }

   for (i = 0; i < myform.ruleSetOid.length; i++)
    if ( myform.ruleSetOid[i].checked == true )
    {
      found = 1;
      break;
    }

   if ( found == 1 )
    return confirm("<bean:message bundle="em" key="emarketing.ruleset.ruleSetSearch.javaScript.alert.deleteRuleSet"/>\n<bean:message bundle="em" key="emarketing.ruleset.ruleSetSearch.javaScript.alert.deleteRuleSetnext"/>");
   else
   {
    alert( "<bean:message bundle="em" key="emarketing.ruleset.ruleSetSearch.javaScript.alert.selectRuleSet"/>")
    return false;
   }
}

function confirmDelete(name){
   return confirm("<bean:message bundle="em" key="emarketing.ruleset.ruleSetSearch.javaScript.alert.deleteRuleSet" />");
}

function onChangeOptions(myform) {
   if( myform.lastModifiedDateOperator.value == '*') {
     myform["lastModifiedDate.month"].disabled= true;
     myform["lastModifiedDate.day"].disabled = true;
     myform["lastModifiedDate.year"].disabled = true;
   }
   else {
     myform["lastModifiedDate.month"].disabled = false;
     myform["lastModifiedDate.day"].disabled = false;
     myform["lastModifiedDate.year"].disabled = false;
   }
     
   return true;
 }
 
function validateForm (form) {
 
   if (form.includeLastModifiedDateFrom.checked &&
       form.includeLastModifiedDateTo.checked)  {
     var dateFrom = getDateOnly("emRuleSetSearchForm","lastModifiedDateFrom");
     var dateTo = getDateOnly("emRuleSetSearchForm","lastModifiedDateTo");
     if (dateTo < dateFrom) {
       alert('<bean:message key="em.ruleset.error.search.dateRange" bundle="em"/>');
       return false;
     }
  }  
  return true;
}
</script>


<%
  String ctxPath = request.getContextPath();
%>


<html:form action="/em/ruleset/ruleSetSearch.do" onsubmit="return validateForm(this);">

	<!--start zone 5 content area-->

<table width="100%" class="zoneFive" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td valign="top" width="100%">
			<div class="pageTitle">
			<logic:equal name="emRuleSetSearchForm" property="showResults" value="false">
				<bean:message bundle="em" key="emarketing.ruleset.ruleSetSearch.pageTitle" />
			</logic:equal>
			<logic:equal name="emRuleSetSearchForm" property="showResults" value="true">
				<bean:message bundle="em" key="emarketing.ruleset.ruleSetSearch.pageTitle" />: 
	  			<bean:write name="emRuleSetSearchForm" property="resultSize" />
				<bean:message bundle="em" key="emarketing.ruleset.ruleSetSearch.pageTitle.suffix.found" />
			</logic:equal>
			</div>

			<div class="pageSubtitle">
				<span class="left">
					<bean:message bundle="em"
					key="emarketing.ruleset.ruleSetSearch.header.ruleSetCriteria" />
				</span>
				<span class="right">
				              <input type="button"  name="newRuleSet"
				                class="inputButton"
				                onClick="createNewRuleSet('/em/ruleset/ruleSetNew.do');"
				                value="<bean:message bundle="em" key="emarketing.ruleset.ruleSetSearch.button.newRuleSet"/>" >
		  		</span>
			</div>

			<table width="100%" border="0" cellspacing="0" cellpadding="0" class="labelForm">
				<tr>
					<td valign="top" wrap width="20%" class="label"><bean:message
						bundle="em"
						key="emarketing.ruleset.ruleSetSearch.lable.ruleSetName" />:</td>
					<td valign="top" class="labelField" width="80%" colSpan="2" ><html:text
						name="emRuleSetSearchForm" property="name" size="31"
						maxlength="80" /></td>
				</tr>
				<tr>
					<td valign="top" wrap width="20%" class="label"><bean:message
						bundle="em" key="emarketing.ruleset.text.description" />:</td>
					<td valign="top" class="labelField" width="80%" colSpan="2">
						<html:textarea
						cols="30" rows="4" name="emRuleSetSearchForm"
						property="description" /></td>
				</tr>
				<tr>
					<td valign="top" wrap width="20%" class="label"><bean:message
						bundle="em" key="em.label.status" />:</td>
					<td valign="top" class="labelField" width="80%" colSpan="2"><html:checkbox
						name="emRuleSetSearchForm" property="statusOnline" /> <bean:message
						bundle="em" key="em.label.online" /> <html:checkbox
						name="emRuleSetSearchForm" property="statusOffline" /> <bean:message
						bundle="em" key="em.label.offline" /></td>
				</tr>
				
				<tr> 
					<td class="label" width="20%">
						<bean:message key="emarketing.ruleset.text.lastModified" bundle="em"/>:
					</td>
					<td class="labelField" width="10%" nowrap>
						<html:checkbox property="includeLastModifiedDateFrom"/>
						<bean:message key="em.label.from" bundle="em"/>
					</td>
					<td class="labelField" width="70%" nowrap>
						<bvhtml:date property="lastModifiedDateFrom"
							onChangeMonth="onChangeMonth"
							onChangeYear="onChangeYear"
							noblank="true"/>
						<a href="JavaScript:datePopup(
							'<html:rewrite page="/mc/calendar.do"/>',
							'emRuleSetSearchForm','lastModifiedDateFrom')"><img
							src="<%= ctxPath %>/mc/images/action/calendar.gif"
							width="22" height="22"
							alt='<bean:message key="image.alt.chooseDate" bundle="em"/>'
							title='<bean:message key="image.alt.chooseDate" bundle="em"/>'
							border="0" align="absmiddle"/></a>
					</td>					
				</tr>
				<tr>
					<td class="label" width="20%">&nbsp;</td>
					<td class="labelField" width="10%" nowrap>
						<html:checkbox property="includeLastModifiedDateTo"/>
						<bean:message key="em.label.to" bundle="em" />
					</td>
					<td class="labelField" width="70%" nowrap>
						<bvhtml:date property="lastModifiedDateTo"
							onChangeMonth="onChangeMonth"
							onChangeYear="onChangeYear"
							noblank="true"/>
						<a href="JavaScript:datePopup(
							'<html:rewrite page="/mc/calendar.do"/>',
							'emRuleSetSearchForm','lastModifiedDateTo')"><img
							src="<%= ctxPath %>/mc/images/action/calendar.gif"
							width="22" height="22"
							alt='<bean:message key="image.alt.chooseDate" bundle="em"/>'
							title='<bean:message key="image.alt.chooseDate" bundle="em"/>'
							border="0" align="absmiddle"/></a>
					</td>
       				</tr>
       				
            			<tr> 
          				<td valign="top" wrap width="20%" class="label">
          				<bean:message bundle="em" key="emarketing.ruleset.ruleSetSearch.lable.sort"/>:
          				</td>
         			 	<td valign="top" class="labelField" width="80%" colSpan="2">
            			<html:select  name ="emRuleSetSearchForm" property = "sortByOperator" size="1">
            			<html:option value=""><bean:message bundle="em" key="em.option.select" /></html:option>
            			<html:option value = "NAME"> 
					<bean:message bundle="em" key="emarketing.ruleset.ruleSetSearch.option.personalizedRuleSetName"/> 
					</html:option>
             			<html:option value = "LAST_MOD_TIME"> 
					<bean:message bundle="em" key="emarketing.ruleset.ruleSetSearch.option.lastModifiedDate"/>
					</html:option>
            			</html:select>
          				</td>
        			</tr>
     			</table>
    
     			<div class="pageButtonWrap" align="right">
         		<html:hidden property="showResults" />
         		<input type="button" name="show" class="inputButton" 
           		onClick="this.form.showResults.value='true';doAction('/em/ruleset/ruleSetSearch.do?actionSearch=true&show=1&pager.offset=0', this.form);"
           		value="<bean:message bundle="em" key="emarketing.ruleset.button.showResults"/>" />
     			</div>    

    <br>
    <logic:equal name="emRuleSetSearchForm" property="showResults" value="true">
    	    <!--start subtitle row-->
          <div class="pageSubtitle">
              <span class="left">
              <bean:message bundle="em" key="emarketing.ruleset.ruleSetSearch.header.searchResult"/>:
              <bean:write  name="emRuleSetSearchForm" property="resultSize"/>
              <bean:message bundle="em" key="emarketing.ruleset.ruleSetSearch.header.suffix.rulesets"/>
		  </span>
           </div>
           <c:if test="${not empty emRuleSetListView.map.rulesetList}">
       <!-- show the button unless having the permission to delete  -->
            <c:if test="${emRuleSetListView.map.deleteAllType}">
             <div class="pageButtonWrap">
              <span class="left">
                    <input type="button" name="selectAll" 
                           class="inputButton" 
                           onClick="check(this.form.ruleSetOid, this);"
                           value="<bean:message bundle="em" key="emarketing.ruleset.button.selectAll"/>" >
		  
                    <input type="button" name="delete" 
                           class="inputButton" value="<bean:message bundle="em" key="button.delete"/>"
                           onclick="if (isAnyChecked(this.form.ruleSetOid, '<bean:message key="emarketing.ruleset.ruleSetSearch.javaScript.alert.selectRuleSet" bundle="em"/>', 
                           '<bean:message key="emarketing.ruleset.ruleSetSearch.javaScript.alert.deleteRuleSets" bundle="em"/>')) doAction('/em/ruleset/ruleSetDelete.do', this.form);">
       		  </span>
            </div>
            </c:if>
          </c:if>
          <!-- End subtitle buttons row -->
         <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Search result table" width="100%">
          
                <tr class="listHeader"> 
                  <th id="Checkboxes" width="3%">&nbsp;</th>
                  <th valign="top" id="RuleSetName" align="left">
                    <bean:message bundle="em" key="emarketing.ruleset.text.name"/>
                  </th>
                  <th valign="top" id="Description" align="left">
                    <bean:message bundle="em" key="emarketing.ruleset.text.description"/>
                  </th>
                  <th valign="top" id="Status" align="left">
		     <bean:message bundle="em" key="em.label.status"/>
                  </th>
                  <th valign="top" id="LastModified" align="left">
                    <bean:message bundle="em" key="emarketing.ruleset.text.lastModified"/>
                  </th>
                  <th valign="top" id="Actions" align="left" width="9%" wrap>
                    <bean:message bundle="em" key="emarketing.ruleset.text.action"/>
                  </th>
                </tr>
                
            <c:if test="${not empty emRuleSetListView.map.rulesetList}">

                <c:forEach var="item" items="${emRuleSetListView.map.rulesetList}" varStatus="index">
		
                 <!-- following code is to display the odd/even records in different colors -->
                 <c:choose>
        	 <c:when test="${(index.count + 1) % 2 == 0}">
	      		<tr class="listEven">
        	 </c:when> 
  	    	 <c:otherwise>
	      		<tr class="listOdd">
	      	 </c:otherwise>
      		 </c:choose> 
                 <td align="center" width="3%" headers="Checkboxes"> 
                   <input type="checkbox" name="ruleSetOid" value='<c:out value="${item.map.oid}" />' 
                   	onclick="update(this.form.ruleSetOid, this.form.selectAll)" />
                 </td>
                 <c:url var="viewUrl" value="/em/ruleset/ruleSetView.do">
		 	<c:param name="oid" value="${item.map.oid}"/>
		  </c:url>
		  <c:url var="editUrl" value="/em/ruleset/ruleSetEdit.do">
			<c:param name="oid" value="${item.map.oid}"/>
		  </c:url>
		  <c:url var="deleteUrl" value="/em/ruleset/ruleSetDelete.do">
			<c:param name="oid" value="${item.map.oid}"/>
		  </c:url>
		  <c:url var="onlineUrl" value="/em/ruleset/rulesetSetOnlineStatus.do">
		         <c:param name="ruleSetOid" value="${item.map.oid}"/>
	  	  </c:url>
		  <c:url var="offlineUrl" value="/em/ruleset/rulesetSetOfflineStatus.do">
		         <c:param name="ruleSetOid" value="${item.map.oid}"/>
	  	  </c:url>
		  
                 <!--- show the name link if with view permission -->
                  <c:if test="${item.map.viewable}">  
                   <td valign="top" headers="RuleSetName">
                   	<a href='<c:out value="${viewUrl}"/>'>
              		<c:out value="${item.map.name}"/></a>
              	   </td>
                   <td valign="top" headers="Description">
              		<c:out value="${item.map.description}"/>
              	   </td>
              	   <td valign="top" headers="Status">
              	   <c:choose>
              	        <c:when test="${item.map.status == 0}">
              	   	    <bean:message bundle="em" key="em.label.offline" />
              	   	</c:when>
              	   	<c:otherwise>
              	   	    <bean:message bundle="em" key="em.label.online" />
              	   	</c:otherwise>
              	   </c:choose>
              	   </td>              	   	
		   <td valign="top" headers="LastModified">
                   	<bean:write name="item" property="lastModifiedTime" formatKey="format.datetime.short" bundle="mc.messages"/>
                   </td>
		   </c:if>
                 
                   <td valign="top" wrap align="left" width="9%" headers="Actions">                 
                  <!--- show the edit button if with edit permission -->
                  <c:if test="${item.map.editable}">
                   	<a href='<c:out value="${editUrl}"/>' >
                   	<c:out value='${editIcon}' escapeXml="false"/></a>
		  </c:if>
		  <c:if test="${item.map.deletable}">
		        <a href='<c:out value="${deleteUrl}"/>' onclick="return confirmDelete();" >
		        <c:out value='${deleteIcon}' escapeXml="false"/></a>
		  </c:if>
		  <c:if test="${item.map.editable}">
		        <c:choose>
		            <c:when test="${item.map.status == 0}">
		                  <a href="<c:out value="${onlineUrl}"/>"><c:out value='${onlineImg}' escapeXml="false"/></a>
		            </c:when>
		            <c:otherwise>
		                  <a href="<c:out value="${offlineUrl}"/>"><c:out value='${offlineImg}' escapeXml="false"/></a>
		            </c:otherwise>
		         </c:choose>
		  </c:if>
                  </td>
                 </tr>
                <!--end list here-->
                </c:forEach>
            </c:if>
            <c:if test="${empty emRuleSetListView.map.rulesetList}">
        	<tr class="listOdd"> 
                 <td colspan="5" valign="top" wrap class="label" width="40%" align="center"> 
                   <bean:message bundle="em" key="emarketing.ruleset.ruleSetSearch.text.noRuleSetFound"/>
                 </td>
           </tr>
           </c:if>
       </table>
       <c:if test="${not empty emRuleSetListView.map.rulesetList}">
       <%@ include file="/mc/common/pager.jsp" %>
	</c:if>
      </logic:equal>
    </td>
  </tr>
</table>
 </html:form> 
</tr>
</td>

</table>

<!--end main content area here-->

<!--end zone 5 content area-->

